﻿using System;
using Informant.Clients.Wpf4;
using Informant.Clients.Wpf4.Credentials;

namespace Informant.Clients.ViewModels.Wpf4
{
	public class LogOnViewModel : LogOnBaseViewModel
	{
		/// <summary>
		/// Command used for logging the user on. Username and Password must be set to enable this command.
		/// </summary>
		/// <value>The log on.</value>
		public DelegateCommand<Object> LogOn { get; set; }

		/// <summary>
		/// Initializes a new instance of the <see cref="LogOnViewModel"/> class.
		/// </summary>
		public LogOnViewModel()
		{
			LogOn = new DelegateCommand<Object>(LogOnExecutedHandler, LogOnCanExecuteHandler, new[] { "Username", "Password" });
			IsoCreds creds = CredentialsHelper.LoadCredsFromStorage();
			if (creds != null)
			{
				Username = creds.Username;
				Password = creds.Password;
				RememberCredentials = true;
			}
		}

		/// <summary>
		/// Removes the cedentials.
		/// </summary>
		protected override void RemoveCedentials()
		{
			CredentialsHelper.RemoveAnySavedCredsFromStorage();
		}
		/// <summary>
		/// Stores the credentials.
		/// </summary>
		protected override void StoreCredentials()
		{
			CredentialsHelper.SaveCredsToStorage(new IsoCreds(Username, Password));
		}
	}
}
